
import java.awt.*;
import javax.swing.*;

/**
 * Caja de listas usadas por la interfaz gráfica.
 *
 * @author Villalva Bueno Arely Eunice
 * @author Romero Rodriguez Gabriel Eduardo
 */
public class ListBoxes extends JPanel {

    static List Instructions = new List();
    static List RF = new List();
    static List Memory = new List();
    static List Messages = new List();
    Canvas dim = new Canvas();

    /**
     * Llena los parametros con los datos correspondientes.
     */
    void buildConstraints(GridBagConstraints gbc, int gx, int gy,
            int gw, int gh, int wx, int wy) {
        gbc.gridx = gx;
        gbc.gridy = gy;
        gbc.gridwidth = gw;
        gbc.gridheight = gh;
        gbc.weightx = wx;
        gbc.weighty = wy;
    }

    ListBoxes() {
        GridBagLayout gridbag = new GridBagLayout();
        GridBagConstraints constraints = new GridBagConstraints();
        setLayout(gridbag);

        // Instruccion etiqueta
        buildConstraints(constraints, 0, 0, 1, 1, 45, 10);
        constraints.fill = GridBagConstraints.BOTH;
        constraints.anchor = GridBagConstraints.WEST;
        Label Linst = new Label("Instrucciones:", Label.LEFT);
        gridbag.setConstraints(Linst, constraints);
        add(Linst);

        // boton invisible usado como separador
        buildConstraints(constraints, 1, 0, 1, 1, 10, 10);
        constraints.fill = GridBagConstraints.NONE;
        constraints.anchor = GridBagConstraints.WEST;
        gridbag.setConstraints(dim, constraints);
        add(dim);


        buildConstraints(constraints, 2, 0, 1, 1, 45, 10);
        constraints.fill = GridBagConstraints.BOTH;
        constraints.anchor = GridBagConstraints.WEST;
        Label Lrf = new Label("Archivo Registro:", Label.LEFT);
        gridbag.setConstraints(Lrf, constraints);
        add(Lrf);


        buildConstraints(constraints, 0, 1, 1, 1, 45, 40);
        constraints.fill = GridBagConstraints.BOTH;
        constraints.anchor = GridBagConstraints.WEST;
        gridbag.setConstraints(Instructions, constraints);
        add(Instructions);

        // RF listbox
        buildConstraints(constraints, 2, 1, 1, 1, 45, 40);
        constraints.fill = GridBagConstraints.BOTH;
        constraints.anchor = GridBagConstraints.WEST;
        gridbag.setConstraints(RF, constraints);
        initRF();
        add(RF);

        //Etiqueta Memoria
        buildConstraints(constraints, 0, 2, 1, 1, 45, 10);
        constraints.fill = GridBagConstraints.NONE;
        constraints.anchor = GridBagConstraints.WEST;
        Label Lmem = new Label("Memoria:", Label.LEFT);
        gridbag.setConstraints(Lmem, constraints);
        add(Lmem);

        // Etiqueta Mensajes
        buildConstraints(constraints, 2, 2, 1, 1, 45, 10);
        constraints.fill = GridBagConstraints.NONE;
        constraints.anchor = GridBagConstraints.WEST;
        Label Lmsg = new Label("Mensajes:", Label.LEFT);
        gridbag.setConstraints(Lmsg, constraints);
        add(Lmsg);

        // Memoria listbox
        buildConstraints(constraints, 0, 3, 1, 1, 45, 40);
        constraints.fill = GridBagConstraints.BOTH;
        constraints.anchor = GridBagConstraints.WEST;
        gridbag.setConstraints(Memory, constraints);
        initMemory();
        add(Memory);

        // Mensajes listbox
        buildConstraints(constraints, 2, 3, 1, 1, 45, 40);
        constraints.fill = GridBagConstraints.BOTH;
        constraints.anchor = GridBagConstraints.WEST;
        gridbag.setConstraints(Messages, constraints);
        add(Messages);
    }

    /**
     * Inicializa los valores de registro en cero.
     */
    public void initRF() {
        int i;
        String temp;

        RF.removeAll();

        for (i = 0; i < 10; i++) {
            temp = "R0" + i + ": 0";
            RF.addItem(temp);
        }
        for (i = 10; i < 32; i++) {
            temp = "R" + i + ": 0";
            RF.addItem(temp);
        }
    }

    /**
     * Inicializa la lista de memoria para que todas las locaciones valgan cero.
     */
    public void initMemory() {
        int i;
        String temp;

        Memory.removeAll();

        for (i = 0; i < 10; i++) {
            temp = "MEM0" + i + ": 0";
            Memory.addItem(temp);
        }
        for (i = 10; i < 32; i++) {
            temp = "MEM" + i + ": 0";
            Memory.addItem(temp);

        }
    }
}
